<?php include('../includes/header.php');?>
<?php include(inc('sql.php'));?>
<?php include(inc('repository.php'));?>
<?php
	$topic=NULL;
	if(!isset($_REQUEST['topic_id'])){
		parameters_check($_REQUEST['group_id']);
		$group_id = intval($_REQUEST['group_id']);
	}else{
		$topic = Topic::get_by_id(intval($_REQUEST['topic_id']));
		if($topic['user_id']!=user_val('id')){
			to_403();
			exit();
		}
		$group_id = $topic['group_id'];
	}
	$group=NULL;
	$group = Group::get_by_id($group_id);
	if(!$group){
		to_404();
		exit();
	}
	
	function value($key){
		global $topic;
		if($topic){
			echo $topic[$key];
		}
		return "";
	}
?>
<div id="main">
	<span class="panel_title">
		<img src="/uploads/groups/group_<?php e($group['id']) ?>.png" width="32" height="32" align="absmiddle"/>
		<span><?php e($group['name']) ?>&nbsp;&gt;
			<?php $topic!=NULL?e('编辑'):e('发新帖')?>
		</span>
	</span>
	<form action="/handlers/post_handler.php?action=save" method="post" id="new_topic_form">
	<div id="new_topic" class="content">
		<input type="hidden" name="id" value="<?php value('id')?>" />
		<input type="hidden" name="group_id" value="<?php e($group['id'])?>"?/>
		<div style="margin-bottom:10px;">
			<label for="title">标题</label>
			<input type="text" name="title" id="title" class="corner"  value="<?php value('title')?>" />
		</div>
		<div>
			<label for="content">正文</label>
			<textarea name="content" id="content" class="corner"><?php value('content')?></textarea>
		</div>
		<div class="response"></div>
	</div>
	<div class="panel_footer">
		<input type="submit" class="btn" value="<?php $topic!=NULL?e('保存修改'):e('发 布')?>" id="btn_create_topic"/>
	</div>
	</form>
</div>
<script type="text/javascript" src="/assets/javascripts/jquery.elastic.min.js"></script>
<?php include_once('group_sidebar.php')?>
<?php get_footer();?>